package wtc.stu.dao;

import wtc.stu.entity.StuEntity;
import wtc.stu.util.DBConnection;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class StuLgoin {
    private DBConnection dbc;
    private Connection conn = null;
    private PreparedStatement pre = null;
    private ResultSet rs;

    public StuLgoin() {
        dbc = new DBConnection();
    }
    public int getLogin(StuEntity user) {
        int count = 0;
        try {
            conn = dbc.getConnection();
            String sql = "select count(*) t from userinfo where uname = ? and upsw = ?";
            pre = conn.prepareStatement(sql);
            pre.setString(1, user.getUname());
            pre.setString(2, user.getUpsw());
            rs = pre.executeQuery();
            while (rs.next()) {
                count = rs.getInt("t");
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        finally {
            dbc.closeAll(pre, conn, rs);
        }
        return count;
    }
}
